package actions;

import bin.Mud;
import items.Item;
import items.ItemType;
import items.containers.Container;

public class ContainerDecider {
    private Mud mudWindow;

    public ContainerDecider(Mud mudWindow) {
        this.mudWindow = mudWindow;
    }

    public boolean isOpen() {
        String command = mudWindow.getCommand();
        return command.startsWith("OPEN");
    }

    public Container itemToOpen() {
        String itemString = mudWindow.getCommand().replaceFirst("OPEN ", "");
        for (Item item : mudWindow.getRoom().getRoomItems()) {
            if (item.getItemType() == ItemType.CONTAINER && (item.getTitle().equalsIgnoreCase(itemString) || item.getShortName().equalsIgnoreCase(itemString))) {
                return (Container) item;
            }
        }
        return null;
    }

    public Container containerToLook() {
        String itemString = mudWindow.getCommand().replaceFirst("LOOK ", "");
        String itemString2 = mudWindow.getCommand().replaceFirst("L ", "");

        for (Item item : mudWindow.getRoom().getRoomItems()) {
            if (item.getItemType() == ItemType.CONTAINER && ((item.getTitle().equalsIgnoreCase(itemString) || item.getShortName().equalsIgnoreCase(itemString))
                || (item.getTitle().equalsIgnoreCase(itemString2) || item.getShortName().equalsIgnoreCase(itemString2)))) {
                return (Container) item;
            }
        }
        return null;
    }
}